<!DOCTYPE html>
{%load staticfiles%}
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body, html {width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
		#allmap{width:100%;height:95%;}
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=8fF825LoEamFjQ5Ab6FTNt4iHtBTcxq0"></script>
    <script src="{% static 'lib/jquery/jquery.js' %}"></script>
    <title>MAP</title>
</head>
<body>
<div id="allmap"></div>
<a class="getpoint">定位</a>
</body>
</html>
<script type="text/javascript">
    // 百度地图API功能
    //GPS坐标
    var x = {{ longitude }};
    var y = {{ latitude }};
    var _x=x;
    var _y=y;
    var ggPoint = new BMap.Point(x,y);
    var getnid=window.location.search.slice(5);
    //地图初始化
    var bm = new BMap.Map("allmap");
    bm.centerAndZoom(ggPoint, 17);
    bm.enableScrollWheelZoom();
    bm.addControl(new BMap.NavigationControl());

    //坐标转换完之后的回调函数
    translateCallback = function (data){
        if(data.status === 0) {
            var marker = new BMap.Marker(data.points[0]);
            bm.addOverlay(marker);
        }
    };
    $('.getpoint').click(function () {
        $.ajax({
                url:'/getpoint/',
                type:'POST',
                data:{nid:getnid}
        })
    });
       $(function () {
        setInterval(aa,4000);
        function aa() {
            $.ajax({
                url:'/map/',
                type:'POST',
                data:{nid:getnid},
                success:function (data) {
                    x=data.longitude;
                    y=data.latitude;
                }
                });
            if(x!==_x||y!==_y){
                setTimeout(function(){
                var convertor = new BMap.Convertor();
                var pointArr = [];
                ggPoint = new BMap.Point(x,y);
                pointArr.push(ggPoint);
                convertor.translate(pointArr, 1, 5, translateCallback)
                    }, 1000);
                _x=x;
                _y=y;
            }
        }})





</script>
